package com.example.tests.pages;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class FilmsPage extends HomePage {
	@FindBy( xpath = "//input[ @id = \"q\" ][ @class = \"inputDefault\"] " )
	WebElement searchInput;
	@FindBy( xpath = "//div[@id=\"results\"]/a")
	List<WebElement> films;
	
	public void printList(){
		System.out.println("Найдено фильмов " + films.size());
		for(WebElement film:films) {
			System.out.println(film.getText());
		}
	}
	
	public void findFilmByTitleAndOpenInfo(String title) {
		for(WebElement film:films) {
			List<WebElement> titles = film.findElements(By.xpath(".//div[ @class=\"title\" ]"));
			System.out.println(titles.get(0).getText());
			if(titles.size() > 0 && titles.get(0).getText().matches(title)) {
				System.out.println("Match!");
				film.click();
				break;
			}
		}
	}
	
	public boolean isOnThisPage() {
		return searchInput.isDisplayed();
	}
	
	
}
